package com.satan.juc.demo02;

/**
 * @Author: Demon
 * @Date: 2024/3/28 17:19
 * @Description:
 **/
public class JoinDemo {
    public static void main(String[] args) {
        Thread previousThread = Thread.currentThread();
        for (int i = 0; i < 10; i++) {
            Thread curThread = new JoinThread(previousThread);
            curThread.start();
            previousThread = curThread;
        }

    }
    static class JoinThread extends Thread {
        private Thread thread;
        public JoinThread(Thread thread) {
            this.thread = thread;
        }

        @Override
        public void run() {
            try {
                thread.join();
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            System.out.println(thread.getName() + " terminate");
        }
    }
}
